import $api from '../../../request/api'
import { Modal, Form } from 'antd'
import { useGetUser } from './useGetUser'

function useChangeUser(path) {
  // 升降级
  function changeLevel(record) {
    let type = ''
    if (record.user_type == 'traffic') {
      type = 'normal'
    } else {
      type = 'traffic'
    }
    $api.postChangeLevel({ id: record.id, type: type }).then((res) => {
      if (res.code == 200) {
        Modal.success({
          content: '成功',
          okText: '确认',
        })
      } else {
        Modal.warning({
          title: '失败',
          content: '出错!',
        })
      }
    })
  }
  // 新增部分
  const [addForm] = Form.useForm()
  const types = [
    { label: 'normal', value: 'normal' },
    { label: 'traffic', value: 'traffic' },
  ]

  // 改变用户登录状态
  const changeStatus = (val, record) => {
    let checked = ''
    if (val == 'false') {
      checked = 'true'
    } else {
      checked = 'false'
    }
    $api.putUserStatus({ checked, id: record.id })
  }

  // 返回值
  return { changeStatus, changeLevel }
}

export { useChangeUser }
